package jmine.tec.web.front.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.web.front.dao.BackOfficeRequestStatusSystemIdentifier;

import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;
import bancosys.tec.persist.persister.annotation.SystemId;

/**
 * Possible command statuses
 * 
 * @author lundberg
 */
@Entity
@Alias("BCOFST")
@Table(name = "BACK_OFFICE_REQUEST_STATUS")
@Documentation("O STATUS DE UMA REQUISICAO A SER ENVIADA AO BACK OFFICE")
@SequenceGenerator(sequenceName = "SEQ_BCOFST", name = "SEQ_BCOFST")
public class BackOfficeRequestStatus extends PersistableBusinessObject {
    private Long id;

    private Long version;

    private String name;

    /**
     * @return the id
     */
    @SystemId
    @Id
    @GeneratedValue(generator = "SEQ_BCOFST")
    @Column(name = "COD_BACK_OFFICE_STATUS", nullable = false)
    @Documentation("CODIGO DO STATUS DA REQUISICAO AO BACK OFFICE.")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the version
     */
    @Version
    @Column(name = "VERSION", nullable = false)
    @Documentation("VERSAO DO REGISTRO.")
    public Long getVersion() {
        return this.version;
    }

    /**
     * @param version the version to set
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * @return the name
     */
    @NaturalKey
    @NotNull
    @Column(name = "NM_STATUS", nullable = false)
    @Documentation("NOME DO STATUS.")
    public String getName() {
        return this.name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Checks if this status corresponds to the given identifier
     * 
     * @param identifier identifier
     * @return boolean
     */
    @Transient
    public boolean isIdentifiedBy(BackOfficeRequestStatusSystemIdentifier identifier) {
        return this.getId().equals(identifier.getSystemId());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return this.getName();
    }
}
